import mysql.connector
conn = mysql.connector.connect(user='xulili', password='456281937',
    host='localhost', port='3306',
    database='student_bd', use_unicode=True)
c = conn.cursor()
def find_nan():
    c.execute('select * from student where sex like "男";')

    for col in (c.description):
         print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
         print(row)
         print(row[1] + row[2])
    c.close()     #关闭游标
    conn.close()  #关闭连接

def find_4():
    c.execute('select * from student where  id < 5;')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print(row)
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_huang():
    c.execute('select * from student where  first_name like "黄" and  last_name like "_";')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print(row)
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_138():
    c.execute('select * from student where  id in (1,3,8);')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print(row)
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_38():
    c.execute('select * from student where  (id >= 3 and id <= 8);')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print(row)
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_nanr():
    c.execute('select * from student where  sex like "男" order by age desc;')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print(row)
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_nvsum():
    c.execute('select * from student where  sex like "女" ;')
    cou = 1
    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        cou += 1
        print(row)
        print(row[1] + row[2])
    print("女生总数:")
    print(cou)
    c.close()  # 关闭游标
    conn.close()  # 关闭连接


def find_avgage():
    c.execute('select * from student  order by age desc;')
    age = 0
    cou = 1


    for row in c:
        age += row[3]
        cou += 1

    print("平均年龄是：")
    print(int(age / cou))
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_avg_age():
    c.execute('select * from student where  sex like "女" order by age desc;')
    age = 0
    cou = 1

    for row in c:
        age += row[3]
        cou += 1
    print("平均女年龄是：")
    print(int(age / cou))

    c.execute('select * from student where  sex like "男" order by age desc;')
    age = 0
    cou = 1

    for row in c:
        age += row[3]
        cou += 1

    print("平均男年龄是：")
    print(int(age / cou))
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

def find_group():
    c.execute('select * from student where  sex like "男" ')

    for col in (c.description):
        print(col[0], end='\t')
    print('\n--------------------------------')

    for row in c:
        print()
        print(row[1] + row[2])
    c.close()  # 关闭游标
    conn.close()  # 关闭连接

find_group()